package Pet.Management.controller;

import Pet.Management.domain.dto.AgeDistributionDTO;
import Pet.Management.domain.dto.GenderDistributionDTO;
import Pet.Management.domain.dto.PetTypeDistributionDTO;
import Pet.Management.domain.dto.RegTrendDTO;
import Pet.Management.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/analysis")
public class AnalysisController {

    @Autowired
    private AnalysisService analysisService;

    /**
     * 获取用户性别分布数据
     */
    @GetMapping("/gender")
    public ResponseEntity<Map<String, Object>> getGenderDistribution() {
        GenderDistributionDTO data = analysisService.getGenderDistribution();
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", data);
        
        return ResponseEntity.ok(response);
    }

    /**
     * 获取用户年龄分布数据
     */
    @GetMapping("/age")
    public ResponseEntity<Map<String, Object>> getAgeDistribution() {
        AgeDistributionDTO data = analysisService.getAgeDistribution();
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", data);
        
        return ResponseEntity.ok(response);
    }

    /**
     * 获取宠物类型分布数据
     */
    @GetMapping("/pet-type")
    public ResponseEntity<Map<String, Object>> getPetTypeDistribution() {
        PetTypeDistributionDTO data = analysisService.getPetTypeDistribution();
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", data);
        
        return ResponseEntity.ok(response);
    }

    /**
     * 获取用户注册趋势数据
     */
    @GetMapping("/reg-trend")
    public ResponseEntity<Map<String, Object>> getRegTrend(@RequestParam(defaultValue = "month") String type) {
        RegTrendDTO data = analysisService.getRegTrend(type);
        
        Map<String, Object> response = new HashMap<>();
        response.put("code", 200);
        response.put("data", data);
        
        return ResponseEntity.ok(response);
    }
} 